{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class="layui-this">区服管理</li>
            <li class=""><a href="{:url('admin/garea/add')}">添加区服</a></li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">

                <form class="layui-form layui-form-pane" action="{:url('admin/garea/index')}" method="get">
                    <div class="layui-inline">
                        <label class="layui-form-label">关键词</label>
                        <div class="layui-input-inline">
                            <input type="text" name="keyword" value="{$keyword}" placeholder="请输入关键词" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">区服状态</label>
                        <div class="layui-input-inline" style="width: 100px;">
                            <select name="status">
                                <option value="0">所有</option>
                                <option value="1" {if condition="$vo.status==1"} selected{/if}>停用</option>
                                <option value="2" {if condition="$vo.status==2"} selected{/if}>启用</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn">搜索</button>
                    </div>
                </form>
                <hr>

                <table class="layui-table">
                    <thead>
                    <tr>
                        <th style="width: 45px;">ID</th>
                        <th style="width: 45px;">游戏ID</th>
                        <th style="width: 45px;">区服ID</th>
                        <th style="width: 45px;">混服ID</th>
                        <th>区服名称</th>
                        <th>开服时间</th>
						<th>资源地址</th>
						<th>IP地址</th>
						<th>端口号</th>
						<th style="width: 80px;">区服状态</th>
                        <th style="width: 25px;">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {foreach name="game_garea" item="vo"}
                    <tr>
                        <td>{$vo.id}</td>
                        <td>{$vo.gid}</td>
	                    <td>{$vo.sid}</td>
                        <td>{$vo.sname}</td>
                        <td>{$vo.agent}</td>
                        <td>{$vo.server_res}</td>
                        <td>{$vo.server_ip}</td>
                        <td>{$vo.server_port}</td>
                        <td>{$vo['open_time']|date='Y-m-d H:i:s'}</td>
						<td class="layui-form">
						    <div class="layui-form layui-form-item">
  								<input lay-skin="switch" lay-filter="status" type="checkbox" {eq name="$vo.status" value="1"}checked="" name="open"{else/}name="close"{/eq} lay-skin="switch" lay-text="开启|关闭" table-value="gamearea" field-value="status" key-value="id" id-value="{$vo.id}" status-value="{$vo.status}">
							</div>
						</td>
                        <td>
                            <a href="{:url('admin/garea/edit',['id'=>$vo['id']])}" class="layui-btn layui-btn-mini">编辑</a>
                        </td>
                    </tr>
                    {/foreach}
                    </tbody>
                </table>
                <!--分页-->
                {$game_garea|raw}
            </div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script>
//Demo
;!function(){
  var layer = layui.layer
  ,form = layui.form;
  
  //监听开启开关
  form.on('switch(swbtn)', function(data){
    var url  = $(this).attr('data-url');
	var type = $(this).attr('data');
	var date = $(this).attr('data2');
	var status = this.checked ? 1:0;
	$.post(url,{id:date,type:type,status:status},function(info){
	    layer.msg(info.msg);
		})
  });
  
};
layui.use('form', function(){
  var form = layui.form;
      laydate = layui.laydate;
	form.on('switch(status)',function(data){
    	var id=($(data.elem).attr('id-value'));
	    var table=($(data.elem).attr("table-value"));
        var field=($(data.elem).attr("field-value"));
        var key=($(data.elem).attr("key-value"));
       $.get("/admin/checkstatus/index",{id:id,table:table,field:field,key:key},function(data){
    		window.location.reload();
    	});
	});
});
</script>
{/block}
